<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>用户列表</title>
    <script type="text/javascript" src="<c:url value='/js/jquery-1.7.1.js'></c:url>"></script>
	<script type="text/javascript">
		function jump(p,s){
			var oForm = document.searchForm?document.searchForm : document.forms[0];
			var inp = document.getElementById('gPage');
			if(isNaN(Number(inp.value.trim()))){
				layer.alert("您输入的页码有误！请重新输入！");
				//选中 pageNum文本框
				inp.select();
				return;
			}  
			
			document.getElementById("pageNum").value = p;
			document.getElementById("pageSize").value = s;
			document.getElementById("searchForm").submit();
		}
	
		function del(id){
			$.post("<%=path%>/user/delUser?id=" + id,function(data){
				if(data.result == "success"){
					alert("删除成功");
					window.location.reload();
				}else{
					alert("删除失败");
				}
			});
		}
	</script>
  </head>
  
  <body>
  	<!-- 搜索栏start -->
   	<table border="1" style="margin:0 auto;width:90%;">
   		<tr>
   			<td>
   				<form id="searchForm" action="<%=path%>/user/getAllUser" method="post">
		    		<input type="hidden"  name="pageNum" id="pageNum" value="${pager.pageNum }"/>
					<input type="hidden"  name="pageSize" id="pageSize"  value="${pager.pageSize }"/>
					用户名:<input name="userName" value="${user.userName }"/>
					密码:<input name="passWord" value="${user.passWord }"/>
					状态:<select name="state">
						<option value="0">--请选择--</option>
						<option value="1" <c:if test="${user.state == 1 }">selected="selected"</c:if>>正常</option>
						<option value="2" <c:if test="${user.state == 2 }">selected="selected"</c:if>>禁用</option>
					</select>
					<input type="submit" value="查询"/>
		    	</form>
   			</td>
   		</tr>
   	</table>
   	<!-- 搜索栏end -->
    
	<table border="1" style="margin:0 auto;width:90%;">
		<tbody>
			<tr>
				<th>用户名</th>
				<th>密码</th>
				<th>状态</th>
				<th>创建时间</th>
				<th>操作/<a href="<%=basePath%>user/toAddUser">添加</a></th>
			</tr>
			<c:if test="${!empty userList }">
				<c:forEach items="${userList}" var="user">
					<tr>
						<td>${user.userName }</td>
						<td>${user.passWord }</td>
						<td>
							<c:if test="${user.state == 1 }">正常</c:if>
							<c:if test="${user.state == 2 }">禁用</c:if>
						</td>
						<td>
							<fmt:formatDate value="${user.createTime }" pattern="yyyy年MM月dd日 HH:mm:ss"/>
						</td>
						<td>
							<a href="<%=basePath%>user/getUser?id=${user.id}">编辑</a>
							<a href="javascript:del('${user.id }')">删除</a>
						</td>
					</tr>				
				</c:forEach>
			</c:if>
			
			<!-- 分页导航  start -->
			<tr>
				<td colspan="5" style="text-align: right;">
					<c:if test="${pager.pageNum <= 1 }">
						<a href="javascript:void(0);" >首页</a>
						<a href="javascript:void(0);" >上一页</a>
					</c:if>
					<c:if test="${pager.pageNum > 1 }">
						<a href="javascript:void(0);"  onclick="jump(1,${pager.pageSize});">首页</a>
						<a href="javascript:void(0);"  onclick="jump(${pager.pageNum-1},${pager.pageSize});" >上一页</a>
					</c:if>
					<c:if test="${pager.pageNum >= pager.pages }">
						<a href="javascript:void(0);">下一页</a>
						<a href="javascript:void(0);" >末页</a>
					</c:if>
					<c:if test="${pager.pageNum < pager.pages }">
						<a href="javascript:void(0);"  onclick="jump(${pager.pageNum+1},${pager.pageSize});">下一页</a>
						<a href="javascript:void(0);"  onclick="jump(${pager.pages },${pager.pageSize});">末页</a>
					</c:if>
					<input id="gPage" type="text" value="${pager.pageNum }"  style="width:20px;height:25px;">
					<a id="go" href="javascript:void(0);" onclick="jump(document.getElementById('gPage').value, ${pager.pageSize })">go</a>
					<p style="display: inline;">共<span>${pager.pageNum }/${pager.pages }</span>页</p>
				</td>
			</tr>
			<!-- 分页导航  end -->
		</tbody>
	</table>
  </body>
</html>
